package de.iritgo.skillfull.component.visitor;

import java.awt.Point;
import java.awt.Rectangle;

import de.iritgo.skillfull.component.motion.MoveRotationComponent;
import de.iritgo.skillfull.component.visual.AnimationRenderComponent;
import de.iritgo.skillfull.component.visual.ImageRenderComponent;
import de.iritgo.skillfull.component.visual.SpriteSheetRenderComponent;

/**
 * Configure the rotation component
 * 
 * @author held
 *
 */
public class MoveRotationVisitor extends BaseVisitor 
{
	private Point dst;
	private boolean done;
	private boolean setDestToMovieRoationCmp;

	float rotation = -1;
	private int special;
	private float direction;
	private Rectangle validArea;
	
	public MoveRotationVisitor (Point destination)
	{
		this.dst = destination;
		this.done = false;
		this.setDestToMovieRoationCmp = true;
	}
	
	public MoveRotationVisitor(int special) 
	{
		this.special = special;
	}

	public MoveRotationVisitor(float direction, Rectangle validArea) 
	{
		this.direction = direction;
		this.validArea = validArea;
		this.done = false;
		this.setDestToMovieRoationCmp = true;
	}

	public boolean isDone ()
	{
		return done;
	}

	public void visit (MoveRotationComponent moveRotationComponent) 
	{
		if (special == 1)
		{
			moveRotationComponent.stop ();
			rotation = moveRotationComponent.getCurrentRotation();
			done = true;
			return;
		}
		
		if (setDestToMovieRoationCmp)
		{
			if (validArea == null)
			{
				moveRotationComponent.moveTo (dst);
			}
			else
			{
				moveRotationComponent.moveTo (direction);
			}
			setDestToMovieRoationCmp = false;
		}
		rotation = moveRotationComponent.getCurrentRotation();
		entity.setRotation (rotation);
		
		if (moveRotationComponent.dstReached ())
		{
			done = true;
		}
	}

	public void visit (ImageRenderComponent renderComponent)
	{
		renderComponent.setRotation (rotation);
	}

	public void visit (AnimationRenderComponent animationRenderComponent)
	{
		animationRenderComponent.setRotation(rotation);
	}

	public void visit(SpriteSheetRenderComponent spriteSheetRenderComponent) 
	{ 
		spriteSheetRenderComponent.setRotation(rotation);
	}

}
